package com.wuhuahe.learning.lagou.service.email.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
@ConfigurationProperties(prefix = "spring.mail")
@RefreshScope
public class MailSenderConfig {

    /*
    host: smtp.qq.com
#    #发送者的邮件的用户名
#    username: 1018281110@qq.com
#    #使用的编码
#    default-encoding: utf-8
#    #移动端客户授权码(在邮箱中设置)
#    password: vdefnsfodvcvbbdh
     */

    private String host;
    private String username;
    private String defaultEncoding;
    private String password;

    @Bean
    @Primary
    @RefreshScope
    public JavaMailSender javaMailSender(){
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();

        javaMailSender.setHost(host);
        javaMailSender.setUsername(username);
        javaMailSender.setDefaultEncoding(defaultEncoding);
        javaMailSender.setPassword(password);

        return javaMailSender;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getDefaultEncoding() {
        return defaultEncoding;
    }

    public void setDefaultEncoding(String defaultEncoding) {
        this.defaultEncoding = defaultEncoding;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
